﻿@using QLNS;
@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Home.cshtml";
    
    
    List<SelectListItem> lstPhuCap = new List<SelectListItem>();
    List<PhuCap> idqlnn = ViewBag.DSPhuCap;
    SelectListItem item0 = new SelectListItem();
    item0.Text = "Không";
    item0.Value = "0";
    lstPhuCap.Add(item0);
    foreach (var l in idqlnn)
    {
        SelectListItem item = new SelectListItem();
        item.Text = l.Ten;
        item.Value = l.ID.ToString();
        lstPhuCap.Add(item);
    }

    List<SelectListItem> listNhomChucVu = new List<SelectListItem>();
    List<tblNhomChucVu> dsNhomChucVu = ViewBag.DSNhomChucVu;
    foreach(var l in dsNhomChucVu){
        SelectListItem item = new SelectListItem();
        item.Text = l.tenNhom;
        item.Value = l.id.ToString();
        listNhomChucVu.Add(item);
    }

    PhongBan dt = ViewBag.phongban;    
    // List root Dept
    List<SelectListItem> listRootDept = new List<SelectListItem>();


    List<PhongBan> root = QLNS.Models.PhongBanModels.GetDSPhongBan(0);
    if (root.Count > 0)
    {


        //Cap 1 la Don vi       
        foreach (var r in root)
        {
            SelectListItem itemr = new SelectListItem();
            itemr.Text = r.TenPhongBan;
            itemr.Value = r.ID.ToString();
            //if (dt.IDParent == r.ID)
            //{
            //    itemr.Selected = true;
            //}
            listRootDept.Add(itemr);
            List<PhongBan> root1 = QLNS.Models.PhongBanModels.GetDSPhongBan(r.ID);
            if (root1.Count > 0)
            {
                foreach (var r1 in root1)
                {
                    SelectListItem itemr1 = new SelectListItem();
                    itemr1.Text = r1.TenPhongBan;
                    itemr1.Value = r1.ID.ToString();
                    //itemr1.Selected = true;
                    //if (dt.IDParent == r1.ID)
                    //{
                    //    itemr1.Selected = true;
                    //}
                    listRootDept.Add(itemr1); 
                    List<PhongBan> root2 = QLNS.Models.PhongBanModels.GetDSPhongBan(r1.ID);
                    if (root2.Count > 0)
                    {
                        foreach (var r2 in root2)
                        {
                            SelectListItem itemr2 = new SelectListItem();
                            itemr2.Text = r2.TenPhongBan;
                            itemr2.Value = r2.ID.ToString();
                            //if (dt.IDParent == r2.ID)
                            //{
                            //    itemr2.Selected = true;
                            //}
                            listRootDept.Add(itemr2); 
                            List<PhongBan> root3 = QLNS.Models.PhongBanModels.GetDSPhongBan(r2.ID);
                            if (root3.Count > 0)
                            {
                                foreach (var r3 in root3)
                                {
                                    SelectListItem itemr3 = new SelectListItem();
                                    itemr3.Text = r3.TenPhongBan;
                                    itemr3.Value = r3.ID.ToString();
                                    //if (dt.IDParent == r3.ID)
                                    //{
                                    //    itemr3.Selected = true;
                                    //}
                                    listRootDept.Add(itemr3);
                                    List<PhongBan> root4 = QLNS.Models.PhongBanModels.GetDSPhongBan(r3.ID);
                                    if (root4.Count > 0)
                                    {
                                        foreach (var r4 in root4)
                                        {
                                            SelectListItem itemr4 = new SelectListItem();
                                            itemr4.Text = r4.TenPhongBan;
                                            itemr4.Value = r4.ID.ToString();
                                            //if (dt.IDParent == r4.ID)
                                            //{
                                            //    itemr4.Selected = true;
                                            //}
                                            listRootDept.Add(itemr4);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
    }
    }
}



@using (Html.BeginForm("Add", "Pos", FormMethod.Post, new { name = "form", id = "submit" }))
 { 
    <div class="toolbar">
        <ul>
            <li><input class="tbtnBack" type="button" value="Quay về" onclick="javascript:history.back()"/>
            </li>
            <li><input class="tbtnSave" type="Submit" value="Lưu" /> 
            </li>
        </ul>
        <div class="ttitle">Thêm mới </div>
    </div>
    <table width="500" border="1">
 
  
  <tr>
    <td>Tên:</td>
    <td>@Html.TextBox("Ten")</td>    
  </tr>
  
  <tr>
    <td>Chọn:</td>
    <td>@Html.DropDownList("ListPhongBan", listRootDept)</td>
  </tr>
  <tr>
    <td>Phụ cấp:
    </td>
    <td>@Html.DropDownList("IDPhuCap", lstPhuCap)
    </td>
  </tr>
  <tr>
    <td>Nhóm Chức Vụ:
    </td>
    <td>@Html.DropDownList("IDNhomChucVu", listNhomChucVu)
    </td>
  </tr>
</table>

        <input id="botton" type="Submit" value="Lưu" class="btnSave"/>
 }

 <script type="text/javascript">
     $("#submit").submit(function () {
         if ($("#Ten").val().toString() == "") {
             jqxAlert.alert("Vui lòng nhập tên chức vụ!");
             return false;
         }
         
     });
 </script>